package cn.xz.tipsum.activity

import android.content.Intent
import android.os.Bundle
import android.util.DisplayMetrics
import android.util.Log
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import cn.xz.tipsum.R
import cn.xz.tipsum.bean.JUMP_TYPE
import cn.xz.tipsum.databinding.ActivityDeviceBinding
import cn.xz.tipsum.dialog.LoadingDialog
import cn.xz.tipsum.dialog.TipsDialog
import cn.xz.tipsum.utils.AppHelper
import cn.xz.tipsum.utils.DownloadUtil
import cn.xz.tipsum.utils.MD5Utils
import java.io.File

class DeviceActivity : AppCompatActivity() {

    private var mDataBind: ActivityDeviceBinding? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
        mDataBind = DataBindingUtil.setContentView(this, R.layout.activity_device)
        initData()
        initEvent()
    }

    private fun initData(){
        mDataBind!!.tv1.text = "设备编号: ${MD5Utils.getMD5(AppHelper.getUUID())}"
        getScreenHW()
    }

    private fun initEvent(){
        mDataBind?.apply {
            tvBack.setOnClickListener {
                finish()
            }
            tvWx.setOnClickListener {
                TipsDialog.newInstance("如果已经有微信了,不用在点这个下载了","不下载","还要下载"){
                    if (!it){
                        LoadingDialog.newInstance("W").show(this@DeviceActivity.supportFragmentManager,"LoadingDialog1")
                    }
                }.show(this@DeviceActivity.supportFragmentManager,"TipsDialog1")
            }
            tvZfb.setOnClickListener {
                TipsDialog.newInstance("如果已经有支付宝了,不用在点这个下载了","不下载","还要下载") {
                    if (!it) {
                        LoadingDialog.newInstance("Z").show(this@DeviceActivity.supportFragmentManager,"LoadingDialog2")
                    }
                }.show(this@DeviceActivity.supportFragmentManager,"TipsDialog2")
            }
            tvVideo.setOnClickListener {
                val intent = Intent(this@DeviceActivity, VideoActivity::class.java)
                startActivity(intent)
            }
            tvBigS.setOnClickListener {
                val intent = Intent(this@DeviceActivity, BigSActivity::class.java)
                startActivity(intent)
            }
        }

    }


    private fun getScreenHW() {
        val metric = DisplayMetrics()
        windowManager.defaultDisplay.getMetrics(metric)
        val width = metric.widthPixels // 屏幕宽度（像素）
        val height = metric.heightPixels // 屏幕高度（像素）
        val densityDpi = metric.densityDpi // 屏幕密度DPI（120 / 160 / 240）
        mDataBind!!.tvId.text = "宽:$width  高:$height  DPI:$densityDpi"
    }
}